from django.db import models
from django.utils import timezone


class BaseModel(models.Model):
    """
    基础模型类
    """
    id = models.BigAutoField(primary_key=True)
    created_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    updated_time = models.DateTimeField(auto_now=True, verbose_name='更新时间')
    is_deleted = models.BooleanField(default=False, verbose_name='是否删除')

    class Meta:
        abstract = True


class BaseModelManager(models.Manager):
    """
    基础模型管理器
    """
    def get_queryset(self):
        """
        默认查询未删除的记录
        """
        return super().get_queryset().filter(is_deleted=False)
    
    def delete(self):
        """
        重写删除方法，实现软删除
        """
        self.is_deleted = True
        self.save()

    def hard_delete(self):
        """
        真实删除方法
        """
        super().delete() 